﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XNAFight.Engine;
using XNAFight.Characters.Core;

namespace HitEditor
{
    public partial class MainWindow : Form
    {
        ListeBMoveSequences bmoves;
        
        public MainWindow()
        {
            InitializeComponent();
            bmoves = new ListeBMoveSequences();

            List <BMove> listBmoves = Enum.GetValues(typeof(BMove)).Cast<BMove>().ToList();
            for (int i = 0; i < listBmoves.Count; i++)
            {
                this.lbBmoves.Items.Add(listBmoves[i].ToString());
            }
        }

        public IntPtr XnaPanelHandle
        {
            get
            {
                return this.xnaPanel.IsHandleCreated ?
                       this.xnaPanel.Handle : IntPtr.Zero;
            }
        }

        public void setXnaPanelDimensions(int _width, int _height)
        {
            this.xnaPanel.Width = _width;
            this.xnaPanel.Height = _height;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.lbBmoves.SelectedItems.Count == 0)
                return;

            int index = this.lbSequence.SelectedIndex;
            if (index < 0)
                index = this.lbSequence.Items.Count;
            else
                index++;

            for (int i = 0; i < this.lbBmoves.SelectedItems.Count; i++)
            {
                this.lbSequence.Items.Insert(index, this.lbBmoves.SelectedItems[i]);
            }
        }

        private void btnAddWith_Click(object sender, EventArgs e)
        {
            if (this.lbBmoves.SelectedItems.Count == 0)
                return;

            if (this.lbSequence.Items.Count == 0)
            {
                this.lbSequence.Items.Add(this.lbBmoves.SelectedItems[0]);
                for (int i = 1; i < this.lbBmoves.SelectedItems.Count; i++)
                {
                    this.lbSequence.Items[0] += "+" + this.lbBmoves.SelectedItems[i].ToString();
                }
            }
            else
            {
                int index = this.lbSequence.SelectedIndex;
                if (index < 0)
                    index = this.lbSequence.Items.Count - 1;

                for (int i = 0; i < this.lbBmoves.SelectedItems.Count; i++)
                {
                    this.lbSequence.Items[index] += "+" + this.lbBmoves.SelectedItems[i].ToString();
                }
            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            int i = 0;
            while (i < this.lbSequence.Items.Count)
            {
                if (this.lbSequence.SelectedIndex == i)
                    this.lbSequence.Items.RemoveAt(i);
                else
                    i++;
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

        }
    }
}
